package Util;

public class Util {
	static public int SumDivisibleByN(int target, int N) {
		int p = target / N;
		return N * p * (p + 1) / 2;
	}
	
	static public int Reverse(int N) {
		int reversed = 0;
		while (N > 0) {
			reversed = 10 * reversed + N % 10;
			N /= 10;
		}
		return reversed;
	}
	
	static public boolean IsPrime(int N) {
		if (N <= 1) {
			return false;
		}
		if (N <= 3) {
			// 2,3
			return true;
		}
		if (N % 2 == 0 || N % 3 == 0) {
			return false;
		}

		int limit = (int) Math.sqrt(N);
		int i = 1;

		while (6 * i - 1 <= limit) {
			if (N % (6 * i - 1) == 0 || N % (6 * i + 1) == 0) {
				return false;
			}
			i++;
		} 

		return true;
	}
	
	static public int SumOf(int N) {
		return N * (N + 1) / 2;
	}
	
	static public int SumOfSquareOf(int N) {
		return (2 * N + 1) * (N + 1) * N / 6;
	}

}
